package fr.ul.ade.secunde.ui.tablet;

import android.content.res.Configuration;
import android.os.Bundle;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import fr.ul.ade.R;
import fr.ul.ade.secunde.ui.HelpActionListener;
import fr.ul.ade.secunde.ui.LessonActionListener;
import fr.ul.ade.secunde.ui.PreferencesActionListener;
import fr.ul.ade.secunde.ui.ScheduleActionListener;

/**
 * Activité principale de notre application, version tablette.
 * 
 * @author Michaël Schnell
 * @since Jul 2, 2013
 * 
 * @version 1.5
 */
public class MainActivity
		extends SherlockFragmentActivity
		implements ScheduleActionListener, LessonActionListener,
		PreferencesActionListener, HelpActionListener {

	private FragmentContentManager contentManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.main_activity);

		/*
		 * Détermination de l'orientation pour l'instanciation du manager
		 * approprié
		 */
		switch (this.getResources().getConfiguration().orientation) {
		case Configuration.ORIENTATION_LANDSCAPE:
			this.contentManager = new LandscapeManager(this);
			break;
		case Configuration.ORIENTATION_PORTRAIT:
		case Configuration.ORIENTATION_UNDEFINED:
		default:
			this.contentManager = new PortraitManager(this);
		}
		this.contentManager.initFragments();
	}

	/*
	 * Gestion du contenu du menu et de l'action bar.
	 */

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return this.contentManager.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return this.contentManager.onOptionsItemSelected(item);
	}

	/*
	 * Gestion du contenu des fragments.
	 */

	@Override
	public void showPreferences() {
		this.contentManager.showPreferences();
	}

	@Override
	public void showNotificationsForm() {
		this.contentManager.showNotificationsForm();
	}

	@Override
	public void showLessonDetails(long scheduleId, long lessonId) {
		this.contentManager.showLessonDetails(scheduleId, lessonId);
	}

	@Override
	public void showScheduleDetails(long scheduleId, String scheduleName) {
		this.contentManager.showScheduleDetails(scheduleId, scheduleName);
	}

	@Override
	public void showCreateForm() {
		this.contentManager.showCreateForm();
	}

	@Override
	public void showEditForm(long scheduleId) {
		this.contentManager.showEditForm(scheduleId);
	}

	@Override
	public void showDeleteForm(long scheduleId, String scheduleName) {
		this.contentManager.showDeleteForm(scheduleId, scheduleName);
	}

	@Override
	public void showLessonList(long scheduleId) {
		this.contentManager.showLessonList(scheduleId);
	}

	@Override
	public void showHelp() {
		this.contentManager.showHelp();
	}

	@Override
	public void onBackPressed() {
		if (this.contentManager.onBackPressed()) {
			super.onBackPressed();
		}
	}

}// class MainActivity